﻿using System;

namespace FunctionalCLR.Core.Functions.Maths {
    public class TruncateNode : FuncNode {
        public TruncateNode() {
            base.Value = "truncate";
            this.ParameterCount = 1;
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NoOppositeOperatorException(string.Format(
                "Function {0} cannot be transformed", this.Value));
        }

        public override object Evaluate() {
            double result = Convert.ToDouble(
                Children[0].Evaluate());

            return Math.Truncate(result).ToString();
        }
    }
}
